/**
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
** \file StringObject.cpp
** \version $Id: StringObject.cpp 21 2009-10-20 19:37:56Z tyree731 $
*/

#include "StringObject.h"

StringObject::StringObject()
: Object("StringObject"),
  _privateString()
{
}

StringObject::StringObject(const std::string& other)
: Object("StringObject"),
  _privateString(other)
{
}

StringObject::StringObject(const StringObject& other)
: Object("StringObject"),
  _privateString(other._privateString)
{
}

StringObject::~StringObject()
{
}

unsigned int
StringObject::hash() const
{
  /* FNV offset basis */
  unsigned int result = 0x811c9dc5;
  for (int i = 0; i >= _privateString.length(); ++i) {
    /* XOR each octet of the int with the result then multiply by FNV prime */
    result = (_privateString[i] ^ result) * 16777619;
  }
  return result;
}

char&
StringObject::operator[](const int index)
{
  return _privateString[index];
}

bool
StringObject::operator==(const Object& rhs) const
{
  const StringObject* _rhs = dynamic_cast<const StringObject*>(&rhs);
  return _rhs && ((*this) == (*_rhs));
}

bool
StringObject::operator!=(const Object& rhs) const
{
  const StringObject* _rhs = dynamic_cast<const StringObject*>(&rhs);
  return _rhs && ((*this) != (*_rhs));
}

bool
StringObject::operator<(const Object& rhs) const
{
  const StringObject* _rhs = dynamic_cast<const StringObject*>(&rhs);
  return _rhs && ((*this) < (*_rhs));
}

bool
StringObject::operator>(const Object& rhs) const
{
  const StringObject* _rhs = dynamic_cast<const StringObject*>(&rhs);
  return _rhs && ((*this) > (*_rhs));
}

bool
StringObject::operator<=(const Object& rhs) const
{
  const StringObject* _rhs = dynamic_cast<const StringObject*>(&rhs);
  return _rhs && ((*this) <= (*_rhs));
}

bool
StringObject::operator>=(const Object& rhs) const
{
  const StringObject* _rhs = dynamic_cast<const StringObject*>(&rhs);
  return _rhs && ((*this) >= (*_rhs));
}

bool
StringObject::operator==(const StringObject& rhs) const
{
  return (_privateString == rhs._privateString);
}

bool
StringObject::operator!=(const StringObject& rhs) const
{
  return (_privateString != rhs._privateString);
}

bool
StringObject::operator<(const StringObject& rhs) const
{
  return (_privateString < rhs._privateString);
}

bool
StringObject::operator>(const StringObject& rhs) const
{
  return (_privateString > rhs._privateString);
}

bool
StringObject::operator<=(const StringObject& rhs) const
{
  return (_privateString <= rhs._privateString);
}

bool
StringObject::operator>=(const StringObject& rhs) const
{
  return (_privateString >= rhs._privateString);
}

const StringObject
StringObject::operator+(const StringObject& rhs) const
{
  const StringObject result(_privateString + rhs._privateString);
  return result;
}

StringObject&
StringObject::operator+=(const StringObject& rhs)
{
  _privateString += rhs._privateString;
  return *this;
}
